<template>
  <!-- 只能有一个根标签 -->
  <!-- 用了一个行列布局 -->
  <el-row type="flex" justify="space-between" align="middle" style="height: 40px; width: 100%;">
    <el-col>
      <span>{{ treeNode.name }}</span>
    </el-col>
    <el-col :span="4">
      <el-row type="flex" justify="end">
        <!-- 两个内容 -->
        <el-col>{{ treeNode.manager }}</el-col>
        <el-col>
          <!-- 下拉菜单 element -->
          <el-dropdown>
            <span>
              操作<i class="el-icon-arrow-down" />
            </span>
            <!-- 下拉菜单 -->
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="add">添加子部门</el-dropdown-item>
              <el-dropdown-item v-if="treeNode.manager !== '负责人'" @click.native="edit">编辑子部门</el-dropdown-item>
              <el-dropdown-item v-if="treeNode.manager !== '负责人'" @click.native="del">删除子部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { delDepartments } from '@/api/departments'
export default {
  name: 'TreeTools',
  components: {},
  props: {
    treeNode: {
      type: Object,
      //   props默认值， 不传就用默认值， 传就用传递的参数
      //   default: function() {
      //     return {
      //       name: '传智播客科技教育股份有限公司',
      //       manager: '负责人'
      //     }
      //   }
      required: true
    }
  },
  data() {
    return {
      flag: false
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    // 删除部门
    async del() {
      // 发送删除的接口
      await delDepartments(this.treeNode.id)
      // 重新拉取tree数据   调用父组件的getDepartments方法
      this.$emit('del')
    },
    // 编辑部门
    edit() {
      this.$emit('editDept', this.treeNode)
    },
    // 添加部门
    add() {
      // 点击添加子部门, 控制父组件的showDialog为true
      this.$emit('addDept', this.treeNode)
    }
  }
}
</script>

<style scoped>

</style>
